
package ui;

import java.awt.Dimension;
// import java.util.HashMap;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
// import javax.swing.JTextField;

public class FormPanel extends JPanel
{
    private static final long serialVersionUID = -2905521178663727771L;
    
    public static final Dimension defaultSize = new Dimension(250, 300);
    public static final String[] deafultLabels = { "Name: ", "Age: ", "Gender: " };
    
    int numLabels = 0;
    int labeledComponents = 0;
    
    // private HashMap<String, JTextField> fields;
    
    public FormPanel( )
    {
	super();
	this.setLayout(null);

	this.setSize(defaultSize);
	this.setPreferredSize(defaultSize);
	this.setMinimumSize(defaultSize);
	this.setMaximumSize(defaultSize);
    }
    
    public void makeLabels(String... labelNames)
    {
	for (int i = 0; i < labelNames.length; i++)
	{
	    String newLabelName = labelNames[i];
	    JLabel label = new JLabel(newLabelName);
	    label.setBounds(20, 30 * numLabels, 150, 50);
	    this.add(label);
	    numLabels++;
	}
	
    }

    public boolean addField()
    {
	if( formIsFull() )
	    return false;
	return true;
    }
    
    private boolean formIsFull()
    {
	return (numLabels == labeledComponents);
    }

    public static void main(String[] args)
    {
	JFrame frame = new JFrame();
	FormPanel form = new FormPanel( );
	form.makeLabels( FormPanel.deafultLabels );
	
	frame.setSize(form.getPreferredSize());
	frame.add(form);
	frame.setVisible(true);
    }
}
